package net.xfok.test.handler;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;

public class XHandler extends Activity {
	private static final String TAG="XHandeler";
	
	protected static final int GUIUPDATEIDENTIFIER = 0x101; 
	private int i=0;
    
    Thread myRefreshThread = null;   
    BounceView myBounceView = null;   
  
    Handler myHandler = new Handler() {  
         public void handleMessage(Message msg) {   
              switch (msg.what) {   
                   case XHandler.GUIUPDATEIDENTIFIER:   
                	   	update();
                        myBounceView.invalidate();  
                        Log.i(TAG, "x="+myBounceView.x);
                        break;   
              }   
              super.handleMessage(msg);   
         }   
    };  
    
    public void onCreate(Bundle savedInstanceState) {   
         super.onCreate(savedInstanceState);   
         this.requestWindowFeature(Window.FEATURE_NO_TITLE);   
  
         this.myBounceView = new BounceView(this);        
         this.setContentView(this.myBounceView);   
//         new Thread(new myThread()).start();  
    }   
    
    public void onResume(){
    	super.onResume();
    	update();
//    	if(!Thread.currentThread().isAlive()){
//    		i=0;
//    		new Thread(new myThread()).start();	
//    	}		
    }
  
    public void onPause(){
    	super.onPause();
    	myHandler.removeMessages(XHandler.GUIUPDATEIDENTIFIER);
    }
//    class myThread implements Runnable {   
//         public void run() {  
//              while (!Thread.currentThread().isInterrupted()) {    
//                   i++;
//                   
//                   Message message = new Message();   
//                   message.what = XHandler.GUIUPDATEIDENTIFIER;   
//                     
//                   XHandler.this.myHandler.sendMessage(message);   
//                   try {   
//                        Thread.sleep(100);    
//                   } catch (InterruptedException e) {   
//                        Thread.currentThread().interrupt();   
//                   }  
//                   if(i>=100){
//                	   Thread.currentThread().interrupt();
//                   }
//              }   
//         }   
//    } 
    private void update(){
    	Message message = new Message();   
    	message.what = XHandler.GUIUPDATEIDENTIFIER;     
    	XHandler.this.myHandler.sendMessageDelayed(message,100);   
    }
}